package com.xinzhi.controller;

import com.alipay.api.AlipayApiException;
import com.xinzhi.model.AlipayBean;
import com.xinzhi.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/* 订单接口 */
@RestController
public class OrderController {
    @Autowired
    private IPayService iPayService;
    /*阿里支付*/
    @PostMapping("/alipay")
    public String alipay(String out_trade_no, String subject, String total_amount, String body) throws AlipayApiException {
        AlipayBean alipayBean = new AlipayBean();
        alipayBean.setBody(body);
        alipayBean.setOut_trade_no(out_trade_no);
        alipayBean.setTotal_amount(new StringBuffer().append(total_amount));
        alipayBean.setSubject(subject);
        return iPayService.Buy(alipayBean);
    }

    @GetMapping("/success")
    public String notifyAlipay() {
        return "支付成功后的回调";
    }

    @GetMapping("/yibu")
    public String returnAlipay() {
        return "这是异步通知接口";
    }
}
